<!DOCTYPE html>
<html height100 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta th:replace="authority/dynamic/common/edit/head"/>
</head>

<body class="childrenBody exclude-table-style" padding10>
<form class="layui-form layui-form-pane" lay-filter="form-dml-column" onsubmit="return false;">
    <input type="hidden" name="id" value="">
    <!--/*@thymesVar id="dynamicTableId" type="java.lang.String"*/-->
    <input type="hidden" name="dynamicTableId" th:value="${dynamicTableId}">

    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm6 zsa-attr-default">
            <label for="T_type" class="layui-form-label"><span class="x-red">*</span>表头类型</label>
            <div class="layui-input-block">
                <select name="type" id="T_type" lay-verify="required" lay-filter="type-select">
                    <option value="">--请选择表头类型--</option>
                    <option value="normal">常规列</option>
                    <option value="checkbox">复选框列</option>
                    <option value="radio">单选框列</option>
                    <option value="numbers">序号列</option>
                    <option value="space">空列</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    定义表头类型（不同类型设置的属性不一样）
                </div>
            </div>
        </div>
        <div class="layui-col-sm6 zsa-attr-dynamic layui-hide zsa-attr-normal zsa-attr-currency">
            <label for="B_isDataCol" class="layui-form-label">是数据列</label>
            <div class="layui-input-block" pane>
                <input type="checkbox" name="isDataCol" id="B_isDataCol" lay-verify="mValidate" lay-skin="switch"
                       checked
                       lay-filter="isDataCol-checkbox" lay-text="是|否">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    是：必须选择数据字段 否：不需选择数据字段
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm8 zsa-attr-dynamic zsa-attr-isData layui-hide">
            <label for="T_dmlColumnId" class="layui-form-label"><span class="x-red">*</span>数据字段</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="T_dmlColumnId" lay-verify="mValidate" mValidate="required"
                       name="dmlColumnId"
                       placeholder="请选择数据字段" autocomplete="off" readonly>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    查询语句中的原始字段
                </div>
            </div>
        </div>
        <div class="layui-col-sm4 zsa-attr-dynamic zsa-attr-currency layui-hide">
            <label for="T_title" class="layui-form-label"><span class="x-red">*</span>表头名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="T_title" name="title" placeholder="表头名称"
                       lay-verify="mValidate" mValidate="required" autocomplete="off">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm6 zsa-attr-dynamic zsa-attr-currency zsa-attr-search-hide layui-hide">
            <label for="T_width" class="layui-form-label">列宽</label>
            <div class="layui-input-block">
                <input type="text" id="T_width" name="width" autocomplete="off" class="layui-input"
                       lay-verify="mValidate" placeholder="自动分配">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    支持 数字/百分比
                </div>
            </div>
        </div>
        <div class="layui-col-sm6 zsa-attr-dynamic zsa-attr-currency zsa-attr-search-hide layui-hide">
            <label for="B_minWidth" class="layui-form-label">列最小宽度</label>
            <div class="layui-input-block">
                <input type="number" id="B_minWidth" name="minWidth" autocomplete="off" class="layui-input"
                       lay-verify="mValidate" placeholder="">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    一般用于列宽自动分配的情况。其优先级高于动态表中的 cellMinWidth 属性
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm4 zsa-attr-default zsa-attr-search-hide">
            <label for="T_fixed" class="layui-form-label">固定列</label>
            <div class="layui-input-block">
                <select name="fixed" id="T_fixed" lay-verify="mValidate">
                    <option value="null" selected>否</option>
                    <option value="left">靠左</option>
                    <option value="right">靠右</option>
                </select>
            </div>
        </div>
        <div class="layui-col-sm4 zsa-attr-default zsa-attr-search-hide">
            <label for="B_hide" class="layui-form-label">默认隐藏</label>
            <div class="layui-input-block">
                <select name="hide" id="B_hide" lay-verify="mValidate">
                    <option value="false" selected>否</option>
                    <option value="true">是</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    初始状态是否隐藏
                </div>
            </div>
        </div>
        <div class="layui-col-sm4 zsa-attr-dynamic zsa-attr-isData zsa-attr-search-hide layui-hide">
            <label for="B_totalRow" class="layui-form-label">列合计</label>
            <div class="layui-input-block">
                <select name="totalRow" id="B_totalRow" lay-verify="mValidate">
                    <option value="false" selected>关闭</option>
                    <option value="true">开启</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    是否开启该列的自动合计，需要动态表格中totalRow（合计行）字段为true
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm4 zsa-attr-default">
            <label for="B_sort" class="layui-form-label"><span class="x-red">*</span>表头序号</label>
            <div class="layui-input-block">
                <input type="number" id="B_sort" name="sort" autocomplete="off" class="layui-input"
                       lay-verify="required|number" placeholder="0">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    表格初始化时以这个序号顺序排列表头
                </div>
            </div>
        </div>

        <div class="layui-col-sm4 zsa-attr-dynamic layui-hide zsa-attr-numbers zsa-attr-isData zsa-attr-search-hide">
            <label for="T_disSort" class="layui-form-label">允许排序</label>
            <div class="layui-input-block">
                <select name="disSort" id="T_disSort" lay-verify="mValidate">
                    <option value="false" selected>否</option>
                    <option value="true">是</option>
                </select>
            </div>
        </div>


        <div class="layui-col-sm4 zsa-attr-dynamic zsa-attr-currency layui-hide zsa-attr-search-hide">
            <label for="B_toolbar" class="layui-form-label">列工具条</label>
            <div class="layui-input-block">
                <select name="toolbar" id="B_toolbar" lay-verify="mValidate">
                    <option value="null">--请选择--</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    必须为页面中存在的工具栏的 id
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm3 zsa-attr-dynamic zsa-attr-currency layui-hide zsa-attr-search-hide">
            <label for="T_unresize" class="layui-form-label">禁用拖拽</label>
            <div class="layui-input-block">
                <select name="unresize" id="T_unresize" lay-verify="mValidate">
                    <option value="false" selected>否</option>
                    <option value="true">是</option>
                </select>
            </div>
        </div>
        <div class="layui-col-sm3 zsa-attr-dynamic zsa-attr-currency layui-hide zsa-attr-search-hide">
            <label for="B_align" class="layui-form-label">文字排列</label>
            <div class="layui-input-block">
                <select name="align" id="B_align" lay-verify="mValidate">
                    <option value="left" selected>默认/左对齐</option>
                    <option value="center">居中</option>
                    <option value="right">右对齐</option>
                </select>
            </div>
        </div>
        <div class="layui-col-sm6 zsa-attr-dynamic zsa-attr-currency layui-hide zsa-attr-search-hide">
            <label for="B_style" class="layui-form-label">自定义样式</label>
            <div class="layui-input-block">
                <input type="text" id="B_style" name="style" autocomplete="off" class="layui-input"
                       placeholder="" lay-verify="mValidate">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm6 zsa-attr-default zsa-attr-search-hide">
            <label for="T_clospan" class="layui-form-label">所占列数</label>
            <div class="layui-input-block">
                <input type="number" id="T_clospan" name="clospan" autocomplete="off" class="layui-input"
                       placeholder="1" lay-verify="mValidate">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    单元格所占列数（默认：1）。用于多级表头
                </div>
            </div>
        </div>
        <div class="layui-col-sm6 zsa-attr-default zsa-attr-search-hide">
            <label for="B_rowspan" class="layui-form-label">所占行数</label>
            <div class="layui-input-block">
                <input type="number" id="B_rowspan" name="rowspan" autocomplete="off"
                       class="layui-input" placeholder='1' lay-verify="mValidate">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    单元格所占行数（默认：1）。用于多级表头
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-form-item zsa-attr-default" pane>
        <label for="C_state" class="layui-form-label"><span class="x-red">*</span>状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="state" id="C_state" lay-skin="switch" checked lay-text="正常|无效">
        </div>
    </div>
    <div class="layui-form-item layui-form-text zsa-attr-dynamic zsa-attr-currency layui-hide zsa-attr-search-hide">
        <label for="T_templet" class="layui-form-label">自定义列模板
            <small>&nbsp; function(d) d：当前行数据</small>
        </label>
        <div class="layui-input-block">
            <pre style="height: 100px;width: 100%" id="T_templet"></pre>
        </div>
    </div>

    <div class="layui-collapse layui-hide" id="div_search">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">搜索配置
                <small>( 条件列表:IN / NOT IN 仅在搜索类型类型为选择框时有效，默认条件:不选择时默认选择第一个有效条件)</small>
            </h2>
            <div class="layui-colla-content">
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-col-sm4">
                        <label for="B_dataType" class="layui-form-label">数据类型</label>
                        <div class="layui-input-block">
                            <input type="text" id="B_dataType" name="search.dataType" autocomplete="off"
                                   class="layui-input layui-disabled" placeholder='' readonly lay-verify="mValidate">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label for="T_editType" class="layui-form-label">搜索类型</label>
                        <div class="layui-input-block">
                            <select name="search.editType" id="T_editType" lay-filter="edit-type" lay-verify="">
                                <option value="text" selected>文字--text</option>
                                <option value="select">选择框--select</option>
                                <option value="date">日期--date</option>
                                <option value="number">数字--number</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-sm4 layui-hide zsa-search-dateType">
                        <label for="T_dateType" class="layui-form-label">日期类型</label>
                        <div class="layui-input-block">
                            <select name="search.dateType" id="T_dateType" lay-verify="">
                                <option value="">--请选择--</option>
                                <option value="year">年</option>
                                <option value="month">年-月</option>
                                <option value="date">年-月-日</option>
                                <option value="time">时:分:秒</option>
                                <option value="datetime">年-月-日 时:分:秒</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-form-item" pane>
                    <label class="layui-form-label"><span class="x-red">*</span>条件列表</label>
                    <div class="layui-input-block">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="=" checked title="等于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value=">" title="大于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="<" title="小于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="<>" title="不等于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="<->" title="包含">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="<-" title="开始于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="->" title="结束于">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="null" title="为空">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="notnull" title="不为空">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="in" title="IN">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="notin" title="NOT IN">
                        <input type="checkbox" lay-filter="checkbox_formulas" value="range" title="范围">
                    </div>
                </div>
                <div class="layui-row layui-form-item" pane>
                    <label class="layui-form-label">默认条件</label>
                    <div class="layui-input-block zsa-search-formula-container">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="=" title="等于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value=">" disabled
                               title="大于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="<" disabled
                               title="小于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="<>" disabled
                               title="不等于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="<->" disabled
                               title="包含">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="<-" disabled
                               title="开始于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="->" disabled
                               title="结束于">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="null" disabled
                               title="为空">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="notnull" disabled
                               title="不为空">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="in" disabled
                               title="IN">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="notin" disabled
                               title="NOT IN">
                        <input type="radio" lay-filter="checkbox_formula" name="search.formula" value="range" disabled
                               title="范围">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text layui-hide zsa-search-dataSource">
                    <label for="T_templet" class="layui-form-label">下拉框数据源（可以是json数组也可以是查询出key、value字段的sql语句）
                        <small>&nbsp; [{key:"男",value:"0"},{key:"女",value:"1"}] / select name key,id value from test
                        </small>
                    </label>
                    <div class="layui-input-block">
                        <pre style="height: 100px;width: 100%" id="T_dataSource"></pre>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-form-item">
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" style="float: right" id="my-submit" lay-filter="submit" lay-submit>保存信息</button>
    </div>
</form>

<script th:replace="authority/dynamic/common/edit/footer"></script>

<script>
    var editor_templet = createAce("T_templet", "ace/mode/javascript");
    var editor_dataSource = createAce("T_dataSource", "ace/mode/json,ace/mode/sql");

    layui.use(['form', 'lutil', 'tableSelect', 'element', 'initPage'], function () {
        var form = layui.form,
            element = layui.element,
            lutil = layui.lutil,
            initPage = layui.initPage,
            tableSelect = layui.tableSelect;

        var defaultSearchs = [{field: "dmlId", value: "[[${dmlId}]]"}];

        initPage.render({successCallback: initSuccess}).addFunction(initToolbarSelects).start();

        function initSuccess() {
            if ("[[${id}]]" !== '') {
                var loding = layer.load(2, {shade: [0.3, '#eee']});
                ajaxRequestByCsrf(content_path + 'authority/dynamic_table_column/detail/[[${id}]].do', {}, function (res) {
                    form.val("form-dml-column", $.extend(res.data, {state: res.data['state'] === 1}));
                    editor_templet.setValue(res.data['templet'] || '');
                    editor_dataSource.setValue(res.data['search.dataSource'] || '');
                    try {
                        var formulas = JSON.parse(res.data['search.formulas']);
                        $('input[type=checkbox][lay-filter=checkbox_formulas]').each(function (i, e) {
                            e.checked = (formulas.indexOf(e.value) > -1);
                        });
                        $('input[type=radio][lay-filter=checkbox_formula]').each(function (i, e) {
                            formulas.indexOf(e.value) > -1 ? $(e).removeAttr('disabled') : $(e).attr('disabled', 'disabled');
                        });
                    } catch (e) {
                    }
                    if (res.data.dmlColumnId) {
                        $('input[name=isDataCol]').prop("checked", "checked");
                        $('form input[name=dmlColumnId]').val(res.data['dmlColumnLabel'] + '（' + res.data['dmlColumnId'] + '）').attr('ts-selected', res.data['dmlColumnId']);
                    } else {
                        $('input[name=isDataCol]').removeAttr('checked');
                    }
                    $('select[name="search.editType"] +.layui-form-select dl dd.layui-this').click();
                    form.render('checkbox', 'form-dml-column');
                    form.render('radio', 'form-dml-column');
                    typeChange(res.data.type);
                    ajaxRequestByCsrf(content_path + 'authority/plat/dml/paging_query.do', {
                        dmlId: '823F4B71D7DB4D949F94C697A0126840',
                        selectType: 2,
                        searchs: JSON.stringify([{field: 'id', value: res.data.dmlColumnId}])
                    }, function (res) {
                        if (res.data.length > 0) {
                            $('input[name="search.dataType"]').val(res.data[0].dataType);
                            $('form input[name=dmlColumnId]').data('zsa-attrs', res.data[0].attrs);
                            $('#T_disSort').val((res.data[0].attrs & 64) === 64 ? 'true' : 'false').attr('disabled', 'disabled');
                            (res.data[0].attrs & 256) === 256 ? $('#div_search').removeClass('layui-hide') : $('#div_search').addClass('layui-hide');
                            (res.data[0].attrs & 512) === 512 ? $('.zsa-attr-search-hide').removeClass('layui-hide') : $('.zsa-attr-search-hide').addClass('layui-hide');
                            form.render('select', 'form-dml-column');
                        }
                    }, null, function (res) {
                        layer.close(loding);
                    });
                }, null, function (res) {
                    layer.close(loding);
                });
            }
        }

        function initToolbarSelects(functionSuccess) {
            ajaxRequestByCsrf(content_path + 'authority/dynamic_table_column/table_toolbars.do', {
                tableId: '[[${dynamicTableId}]]'
            }, function (res) {
                $.each(res.data, function (i, e) {
                    $("#B_toolbar").append($('<option value="' + e['id'] + '">' + e['name'] + '</option>'))
                });
                form.render('select', 'form-dml-column');
            }, null, function () {
                functionSuccess();
            })
        }

        tableSelect.render({
            elem: '#T_dmlColumnId',	//定义输入框input对象 必填
            checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'caption',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '模糊搜索 字段中文名',	//搜索输入框的提示文字 默认关键词搜索
            searchCallback: function (table, data) {
                var searchs = [];
                $.each(data.field, function (i, e) {
                    searchs.push({field: i, formula: '<->', value: e});
                });
                table.query({searchs: JSON.stringify(searchs.concat(defaultSearchs))});
            },
            table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url: content_path + 'authority/plat/dml/paging_query.do',
                where: {
                    dmlId: '823F4B71D7DB4D949F94C697A0126840',
                    selectType: 2,
                    searchs: JSON.stringify(defaultSearchs)
                },
                headers: {'[[${_csrf.headerName}]]': '[[${_csrf.token}]]'},
                cols: [
                    [
                        {type: 'radio'},
                        {field: 'id', title: 'ID'},
                        {field: 'name', title: '字段名称'},
                        {field: 'label', title: '字段别名'},
                        {field: 'caption', title: '字段中文名'},
                        {
                            field: 'lx', title: '类型', templet: function (d) {
                                return (d.attrs & 512) === 512 ? '一般' : '仅搜索';
                            }
                        }
                    ]
                ]
            },
            done: function (elem, data) {
                if (data.data.length > 0) {
                    $(elem).val(data.data[0].label + " （" + data.data[0].id + "）").data('zsa-attrs', data.data[0].attrs);
                    $('#T_title').val(data.data[0].caption);
                    $('#B_sort').val(data.data[0].columnIndex);
                    $('input[name="search.dataType"]').val(data.data[0].dataType);
                    $('#T_disSort').val((data.data[0].attrs & 64) === 64 ? 'true' : 'false').attr('disabled', 'disabled');
                    (data.data[0].attrs & 256) === 256 ? $('#div_search').removeClass('layui-hide') : $('#div_search').addClass('layui-hide');
                    (data.data[0].attrs & 512) === 512 ? $('.zsa-attr-search-hide').removeClass('layui-hide') : $('.zsa-attr-search-hide').addClass('layui-hide');
                    form.render('select', 'form-dml-column');
                } else {
                    $('#T_title').val('');
                    $('input[name="search.dataType"]').val('');
                    $(elem).val('');
                    $('#T_disSort').removeAttr('disabled');
                    $('#div_search').addClass('layui-hide')
                }
            }
        });


        form.verify({
            mValidate: function (value, item) { //value：表单的值、item：表单的DOM对象
                if ($(item).closest('.zsa-attr-dynamic').hasClass('layui-hide')) {
                    var name = $(item).attr('name');
                    $(item).removeAttr('name'), $(item).data('zsa-temp-name', name);
                    return;
                } else {
                    var name = $(item).data('zsa-temp-name');
                    name && $(item).attr('name', name);
                }
                var mValidate = ($(item).attr('mValidate') || '').split('|');
                for (var i = 0; i < mValidate.length; i++) {
                    if (mValidate[0] === 'required' && !/[\S]+/.test(value))
                        return '必填字段不能为空';
                }

            }
        });

        form.on('select(type-select)', function (data) {
            typeChange(data.value);
        });

        form.on('select(edit-type)', function (data) {
            var dataTypeElem = $('.zsa-search-dateType');
            var dataSourceElem = $('.zsa-search-dataSource');
            switch (data.value) {
                case 'date':
                    dataTypeElem.removeClass('layui-hide');
                    dataSourceElem.addClass('layui-hide');
                    $('select[name="search.dateType"]').val() === '' && $('select[name="search.dateType"]').val('date')
                        , form.render('select', 'form-dml-column');
                    break;
                case 'select':
                    dataSourceElem.removeClass('layui-hide');
                    dataTypeElem.addClass('layui-hide');
                    break;
                default:
                    dataTypeElem.addClass('layui-hide'), dataSourceElem.addClass('layui-hide');
            }
        });

        form.on('checkbox(checkbox_formulas)', function (data) {
            var radio = $('.zsa-search-formula-container').find('input[type=radio][lay-filter=checkbox_formula][value="' + data.value + '"]');
            data.elem.checked ? radio.removeAttr('disabled') : (radio.attr('disabled', 'disabled'), radio.prop('checked', false));
            form.render('radio', 'form-dml-column');
        });

        form.on('switch(isDataCol-checkbox)', function (data) {
            if (data.elem.checked === false)
                $('T_dmlColumnId').val('').removeAttr('ts-selected').removeData('zsa-attrs');
            displayAttrs(data.elem.checked);
        });

        function typeChange(value) {
            $('form .zsa-attr-dynamic').each(function (i, e) {
                if ($(this).hasClass('zsa-attr-' + value))
                    $(this).removeClass('layui-hide');
                else $(this).addClass('layui-hide');
            });
            $('.zsa-attr-default').removeClass('layui-hide');
            if (value === 'normal')
                displayAttrs($('input[lay-filter=isDataCol-checkbox]')[0].checked);
        }

        function displayAttrs(tag) {
            $('form .zsa-attr-dynamic').each(function (i, e) {
                if ($(this).hasClass('zsa-attr-currency') || (tag && $(this).hasClass('zsa-attr-isData')))
                    $(this).removeClass('layui-hide');
                else $(this).addClass('layui-hide');
            });
            var attrs = $('#T_dmlColumnId').data('zsa-attrs');
            if (attrs === undefined) return;
            (attrs & 512) === 512 ? $('.zsa-attr-search-hide').removeClass('layui-hide') : $('.zsa-attr-search-hide').addClass('layui-hide');

        }

        form.on('submit(submit)', function (formData) {
            var templet = editor_templet.getValue(), dataSource = editor_dataSource.getValue(), formulas = [];
            $('input[type=checkbox][lay-filter=checkbox_formulas]').each(function (i, e) {
                if (e.checked) formulas.push(e.value);
            });
            if ($('#div_search').hasClass('layui-hide')) {
                if (formData.field['search.editType'] === 'select' && (dataSource === undefined || dataSource.trim() === ''))
                    return lutil.error_alert("搜索框类型为select时，请设置下拉框数据源"), false;
                if (formData.field['search.editType'] === 'date' && formData.field['search.dateType'] === '')
                    formData.field['search.dateType'] = 'date';
                if (formulas.length === 0) return lutil.error_alert("请设置搜索框条件列表"), false;
            }
            var loading = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/dynamic_table_column/save.do', $.extend(formData.field, {
                templet: templet,
                state: formData.field['state'] ? 1 : 0,
                dmlColumnId: $(formData.form).find('input[name=dmlColumnId]').attr('ts-selected'),
                "search.dataSource": dataSource,
                "search.formulas": JSON.stringify(formulas)
            }), function (res) {
                lutil.success_msg(res.message);
                var index = window.name && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }, null, function (res) {
                layer.close(loading);
            });
            return false;
        });


    });

</script>
</body>
</html>